/**
 * 
 */
package com.google.code.cisx.converters;

import com.google.code.cisx.client.dto.ProjectDeveloperViewHelper;
import com.google.code.cisx.model.project.ProjectDeveloper;

import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Map;

/**
 * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
 * @since 1.0
 * @version $Id: ProjectDeveloperConverter.java 113 2008-01-12 05:58:36Z
 *          rahul.thakur.xdev $
 */
public class ProjectDeveloperConverter extends CommonConverter implements Converter {

  /**
   * 
   */
  public ProjectDeveloperConverter() {
    super();
    // TODO Auto-generated constructor stub
  }

  /**
   * @param bub
   */
  public ProjectDeveloperConverter(BeanUtilsBeanExtended bub) {
    super(bub);
    // TODO Auto-generated constructor stub
  }

  /**
   * Commons Logging.
   */
  private static final Log log = LogFactory.getLog(ProjectDeveloperConverter.class);

  /**
   * {@inheritDoc}
   * 
   * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class,
   *      java.lang.Object)
   */
  public Object convert(Class type, Object value) {
    Object retValue = null;
    try {
      Map description = beanUtilsBean.describe(value);
      if (type == ProjectDeveloper.class)
        retValue = new ProjectDeveloperViewHelper();
      else if (type == ProjectDeveloperViewHelper.class)
        retValue = new ProjectDeveloper();
      beanUtilsBean.populate(retValue, description);
    } catch (Exception e) {
      throw new ConversionException(e);
    }
    return retValue;
  }

}
